package top.lemna.account.persistence;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Index;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import top.lemna.common.Amount;

/**
 * 账户表
 */
@Getter
@Setter
@Builder
@ToString()
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@Entity
@EqualsAndHashCode(callSuper = false)
@Table(//
        name = "ac_account", //
        indexes = { @Index(columnList = "principalId") } //
)
public class AccountPo {
    /** 账户ID */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    /** 身份ID 一般填外部对象ID*/
    @NotEmpty
    @lombok.NonNull
    @Column(columnDefinition = "bigint(19) NOT NULL COMMENT '身份ID'")
    private String principalId;
    
    /** 账户名称 */
    @NotNull
    @lombok.NonNull
    @Column(columnDefinition = "varchar(64) NOT NULL COMMENT '账户名称'")
    private String name;

    /** 账户余额  */
    @NotNull
    @Builder.Default
    @Convert(converter = AmountConverter.class)
    @Column(columnDefinition = "DECIMAL(19,2) DEFAULT '0.00' COMMENT '操作后余额'")
    private Amount balance = new Amount();

    /** 冻结金额 可以大于账户余额 */
    @NotNull
    @Builder.Default
    @Convert(converter = AmountConverter.class)
    @Column(columnDefinition = "DECIMAL(19,2) DEFAULT '0.00' COMMENT '冻结金额'")
    private Amount freeze= new Amount();

    /** 是否锁定 */
    @NotNull
    @Builder.Default
    @Enumerated(EnumType.STRING)
    @Column(columnDefinition = "varchar(32) NOT NULL COMMENT '是否锁定'")
    private YesNo block = YesNo.NO;


    
}
